-language: cpp
-compiler:
- - gcc
-sudo: required
-before_install:
- - sudo add-apt-repository -y ppa:chris-lea/node.js
- - sudo apt-get update
- - sudo apt-get install nodejs -y
- - sudo apt-get install doxygen -y
- - sudo npm install -g mocha
- - sudo npm install -g node-gyp
- - sudo npm install
-script: make test VERBOSE=1 && make package VERBOSE=1 && make node-test
+language: node_js
+
+cache:
+ npm: true
+ ccache: true
+
+node_js:
+ - stable
+ - 10
+ - 8
+ - 6
+
+os:
+ - linux
+ - osx
+
+addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ packages:
+ - doxygen
+ - g++-4.8
+
+# Install scripts. (runs after repo cloning)
+install:
+ - if [ $TRAVIS_OS_NAME == "linux" ]; then export CXX=g++-4.8; fi
+ # install modules
+ - npm install --build-from-source
+
+# Post-install test scripts.
+script:
+ - export PATH="/usr/lib/ccache/:$PATH"
+ - if [ $TRAVIS_OS_NAME == "linux" ] && [ $TRAVIS_NODE_VERSION == "stable" ]; then
+ make test VERBOSE=1;
+ make package VERBOSE=1;
+ fi
+
+ - npm test
+
+after_success:
+ - npm run deploy
# Open Chinese Convert 開放中文轉換
[  ](https://bintray.com/byvoid/opencc/OpenCC/_latestVersion)
-[](https://travis-ci.org/BYVoid/OpenCC)
+[](https://travis-ci.org/BYVoid/OpenCC)
+[](https://ci.appveyor.com/project/Carbo/OpenCC)
## Introduction 介紹
See https://github.com/gelosie/OpenCC/tree/master/iOS
+Or [SwiftyOpenCC](https://github.com/XQS6LB3A/SwiftyOpenCC)
+
### Android
See [android-opencc](https://github.com/qichuan/android-opencc)
## Projects using Opencc 使用OpenCC的項目
-* [ibus-pinyin](http://code.google.com/p/ibus/)
-* [fcitx](http://code.google.com/p/fcitx/)
-* [rimeime](http://code.google.com/p/rimeime/)
+* [ibus-pinyin](https://github.com/ibus/ibus-pinyin)
+* [fcitx](https://github.com/fcitx/fcitx)
+* [rimeime](https://rime.im/)
* [libgooglepinyin](http://code.google.com/p/libgooglepinyin/)
* [ibus-libpinyin](https://github.com/libpinyin/ibus-libpinyin)
* [BYVBlog](https://github.com/byvoid/byvblog)
-* [豆瓣同城微信](http://weixinqiao.com/douban-event/)
* [alfred-chinese-converter](https://github.com/amowu/alfred-chinese-converter)
* [GoldenDict](https://github.com/goldendict/goldendict)
--- /dev/null
+version: "{build}"
+skip_branch_with_pr: true
+skip_tags: true
+build: off
+
+environment:
+ matrix:
+ - nodejs_version: stable
+ - nodejs_version: 10
+ - nodejs_version: 8
+ - nodejs_version: 6
+
+platform:
+ - x64
+ - x86
+
+# Install scripts. (runs after repo cloning)
+install:
+ # install Node.js
+ - ps: Install-Product node $env:nodejs_version $env:platform
+ # Get the latest stable version of npm
+ - npm -g i npm@latest
+ # install modules
+ - appveyor-retry call npm install --build-from-source
+
+# to run your custom scripts instead of automatic tests
+test_script:
+ - IF %nodejs_version%==stable cmake -H. -Bbuild -G"Visual Studio 12"
+ - IF %nodejs_version%==stable cmake --build build --config Release --target install
+ - npm test
+
+# pushing entire folder as a zip archive
+artifacts:
+ - path: build/src/tools/Release
+ name: OpenCC
+ type: zip
+
+# to run your custom scripts instead of provider deployments
+deploy_script:
+ - npm run deploy
"node/global.gypi",
"node/configs.gypi",
"node/dicts.gypi",
- "node/node_binding.gypi",
+ "node/node_opencc.gypi",
]
}
化学工厂 化學工廠
化学弹药 化學彈藥
化学当量 化學當量
-化学战斗部 化學戰斗部
+化学战斗部 化學戰鬥部
化学系 化學系
化学纤维 化學纖維
化工厂 化工廠
杨胜旭 楊勝旭
杨致远 楊致遠
杨苏棣 楊甦棣
-杨采妮 楊採妮
+杨采妮 楊采妮
杨雅筑 楊雅筑
杪秋 杪秋
杭丁顿舞蹈症 杭丁頓舞蹈症
核当量 核當量
核心 核心
核战 核戰
-核战斗部 核戰斗部
+核战斗部 核戰鬥部
核批 覈批
核技术 核技術
核报 覈報
间深里 間深裏
闵凶 閔凶
闵子里 閔子裏
-闵采尔 閔採爾
+闵采尔 閔采爾
闷出 悶出
闷在心里 悶在心裏
闷板 悶板
+++ /dev/null
-#include <iostream>
-#include <nan.h>
-
-#include "Config.hpp"
-#include "Converter.hpp"
-#include "DictConverter.hpp"
-
-// For faster build
-#include "BinaryDict.cpp"
-#include "Config.cpp"
-#include "Conversion.cpp"
-#include "ConversionChain.cpp"
-#include "Converter.cpp"
-#include "DartsDict.cpp"
-#include "Dict.cpp"
-#include "DictConverter.cpp"
-#include "DictEntry.cpp"
-#include "DictGroup.cpp"
-#include "MaxMatchSegmentation.cpp"
-#include "Segmentation.cpp"
-#include "TextDict.cpp"
-#include "UTF8Util.cpp"
-
-using namespace opencc;
-
-string ToUtf8String(const v8::Local<v8::Value>& val) {
- Nan::Utf8String utf8(val);
- return string(*utf8);
-}
-
-class OpenccBinding : public Nan::ObjectWrap {
- struct ConvertRequest {
- OpenccBinding* instance;
- string input;
- string output;
- Nan::Callback *callback;
- Optional<opencc::Exception> ex;
-
- ConvertRequest()
- : instance(nullptr), ex(Optional<opencc::Exception>::Null()) {
- }
- };
-
- Config config_;
- const ConverterPtr converter_;
- public:
- explicit OpenccBinding(const string configFileName)
- : config_(),
- converter_(config_.NewFromFile(configFileName)) {}
-
- virtual ~OpenccBinding() {
- }
-
- string Convert(const string& input) {
- return converter_->Convert(input);
- }
-
- static NAN_METHOD(Version) {
- info.GetReturnValue().Set(Nan::New<v8::String>(VERSION).ToLocalChecked());
- }
-
- static NAN_METHOD(New) {
- OpenccBinding* instance;
-
- try {
- if (info.Length() >= 1 && info[0]->IsString()) {
- const string configFile = ToUtf8String(info[0]);
- instance = new OpenccBinding(configFile);
- } else {
- instance = new OpenccBinding("s2t.json");
- }
- } catch (opencc::Exception& e) {
- Nan::ThrowError(e.what());
- return;
- }
-
- instance->Wrap(info.This());
- info.GetReturnValue().Set(info.This());
- }
-
- static NAN_METHOD(Convert) {
- if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
- Nan::ThrowTypeError("Wrong arguments");
- return;
- }
-
- ConvertRequest* conv_data = new ConvertRequest;
- conv_data->instance = Nan::ObjectWrap::Unwrap<OpenccBinding>(info.This());
- conv_data->input = ToUtf8String(info[0]);
- conv_data->callback = new Nan::Callback(info[1].As<v8::Function>());
- conv_data->ex = Optional<opencc::Exception>::Null();
- uv_work_t* req = new uv_work_t;
- req->data = conv_data;
- uv_queue_work(uv_default_loop(), req, DoConvert, (uv_after_work_cb)AfterConvert);
-
- return;
- }
-
- static void DoConvert(uv_work_t* req) {
- ConvertRequest* conv_data = static_cast<ConvertRequest*>(req->data);
- OpenccBinding* instance = conv_data->instance;
- try {
- conv_data->output = instance->Convert(conv_data->input);
- } catch (opencc::Exception& e) {
- conv_data->ex = Optional<opencc::Exception>(e);
- }
- }
-
- static void AfterConvert(uv_work_t* req) {
- Nan::HandleScope scope;
- ConvertRequest* conv_data = static_cast<ConvertRequest*>(req->data);
- v8::Local<v8::Value> err = Nan::Undefined();
- v8::Local<v8::String> converted = Nan::New(conv_data->output.c_str()).ToLocalChecked();
- if (!conv_data->ex.IsNull()) {
- err = Nan::New(conv_data->ex.Get().what()).ToLocalChecked();
- }
- const unsigned argc = 2;
- v8::Local<v8::Value> argv[argc] = {
- err,
- converted
- };
- conv_data->callback->Call(argc, argv);
- delete conv_data;
- delete req;
- }
-
- static NAN_METHOD(ConvertSync) {
- if (info.Length() < 1 || !info[0]->IsString()) {
- Nan::ThrowTypeError("Wrong arguments");
- return;
- }
-
- OpenccBinding* instance = Nan::ObjectWrap::Unwrap<OpenccBinding>(info.This());
-
- const string input = ToUtf8String(info[0]);
- string output;
- try {
- output = instance->Convert(input);
- } catch (opencc::Exception& e) {
- Nan::ThrowError(e.what());
- return;
- }
-
- v8::Local<v8::String> converted = Nan::New(output.c_str()).ToLocalChecked();
- info.GetReturnValue().Set(converted);
- }
-
- static NAN_METHOD(GenerateDict) {
- if (info.Length() < 4 || !info[0]->IsString() || !info[1]->IsString()
- || !info[2]->IsString() || !info[3]->IsString()) {
- Nan::ThrowTypeError("Wrong arguments");
- return;
- }
- const string inputFileName = ToUtf8String(info[0]);
- const string outputFileName = ToUtf8String(info[1]);
- const string formatFrom = ToUtf8String(info[2]);
- const string formatTo = ToUtf8String(info[3]);
- try {
- opencc::ConvertDictionary(inputFileName, outputFileName, formatFrom, formatTo);
- } catch (opencc::Exception& e) {
- Nan::ThrowError(e.what());
- }
- }
-
- static NAN_MODULE_INIT(Init) {
- // Prepare constructor template
- v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(OpenccBinding::New);
- tpl->SetClassName(Nan::New("Opencc").ToLocalChecked());
- tpl->InstanceTemplate()->SetInternalFieldCount(1);
- // Methods
- Nan::SetMethod(tpl, "version", Version);
- Nan::SetMethod(tpl, "generateDict", GenerateDict);
- // Prototype
- Nan::SetPrototypeMethod(tpl, "convert", Convert);
- Nan::SetPrototypeMethod(tpl, "convertSync", ConvertSync);
- // Constructor
- v8::Local<v8::Function> cons = Nan::GetFunction(tpl).ToLocalChecked();
- Nan::Set(target, Nan::New("Opencc").ToLocalChecked(), cons);
- }
-};
-
-NODE_MODULE(binding, OpenccBinding::Init);
"action": ["node", "<(cmd)", "<(input)", "<@(_outputs)"]
}],
"dependencies": [
- "binding"
+ "opencc"
]
}]
}
+++ /dev/null
-{
- "targets": [{
- "target_name": "binding",
- "sources": [
- "../node/binding.cc",
- ],
- "include_dirs": [
- "../src",
- "../deps/darts-clone",
- "../deps/rapidjson-0.11",
- "<!(node -e \"require('nan')\")"
- ]
- }]
-}
--- /dev/null
+{
+ "targets": [{
+ "target_name": "opencc",
+ "sources": [
+ "../node/opencc.cc",
+ ],
+ "include_dirs": [
+ "../src",
+ "../deps/darts-clone",
+ "../deps/rapidjson-0.11",
+ "<!(node -e \"require('nan')\")"
+ ]
+ }]
+}
--- /dev/null
+#include <iostream>
+#include <nan.h>
+
+#include "Config.hpp"
+#include "Converter.hpp"
+#include "DictConverter.hpp"
+
+// For faster build
+#include "BinaryDict.cpp"
+#include "Config.cpp"
+#include "Conversion.cpp"
+#include "ConversionChain.cpp"
+#include "Converter.cpp"
+#include "DartsDict.cpp"
+#include "Dict.cpp"
+#include "DictConverter.cpp"
+#include "DictEntry.cpp"
+#include "DictGroup.cpp"
+#include "MaxMatchSegmentation.cpp"
+#include "Segmentation.cpp"
+#include "TextDict.cpp"
+#include "UTF8Util.cpp"
+
+using namespace opencc;
+
+string ToUtf8String(const v8::Local<v8::Value>& val) {
+ Nan::Utf8String utf8(val);
+ return string(*utf8);
+}
+
+class OpenccBinding : public Nan::ObjectWrap {
+ struct ConvertRequest {
+ OpenccBinding* instance;
+ string input;
+ string output;
+ Nan::Callback *callback;
+ Optional<opencc::Exception> ex;
+
+ ConvertRequest()
+ : instance(nullptr), ex(Optional<opencc::Exception>::Null()) {
+ }
+ };
+
+ Config config_;
+ const ConverterPtr converter_;
+ public:
+ explicit OpenccBinding(const string configFileName)
+ : config_(),
+ converter_(config_.NewFromFile(configFileName)) {}
+
+ virtual ~OpenccBinding() {
+ }
+
+ string Convert(const string& input) {
+ return converter_->Convert(input);
+ }
+
+ static NAN_METHOD(Version) {
+ info.GetReturnValue().Set(Nan::New<v8::String>(VERSION).ToLocalChecked());
+ }
+
+ static NAN_METHOD(New) {
+ OpenccBinding* instance;
+
+ try {
+ if (info.Length() >= 1 && info[0]->IsString()) {
+ const string configFile = ToUtf8String(info[0]);
+ instance = new OpenccBinding(configFile);
+ } else {
+ instance = new OpenccBinding("s2t.json");
+ }
+ } catch (opencc::Exception& e) {
+ Nan::ThrowError(e.what());
+ return;
+ }
+
+ instance->Wrap(info.This());
+ info.GetReturnValue().Set(info.This());
+ }
+
+ static NAN_METHOD(Convert) {
+ if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
+ Nan::ThrowTypeError("Wrong arguments");
+ return;
+ }
+
+ ConvertRequest* conv_data = new ConvertRequest;
+ conv_data->instance = Nan::ObjectWrap::Unwrap<OpenccBinding>(info.This());
+ conv_data->input = ToUtf8String(info[0]);
+ conv_data->callback = new Nan::Callback(info[1].As<v8::Function>());
+ conv_data->ex = Optional<opencc::Exception>::Null();
+ uv_work_t* req = new uv_work_t;
+ req->data = conv_data;
+ uv_queue_work(uv_default_loop(), req, DoConvert, (uv_after_work_cb)AfterConvert);
+
+ return;
+ }
+
+ static void DoConvert(uv_work_t* req) {
+ ConvertRequest* conv_data = static_cast<ConvertRequest*>(req->data);
+ OpenccBinding* instance = conv_data->instance;
+ try {
+ conv_data->output = instance->Convert(conv_data->input);
+ } catch (opencc::Exception& e) {
+ conv_data->ex = Optional<opencc::Exception>(e);
+ }
+ }
+
+ static void AfterConvert(uv_work_t* req) {
+ Nan::HandleScope scope;
+ ConvertRequest* conv_data = static_cast<ConvertRequest*>(req->data);
+ v8::Local<v8::Value> err = Nan::Undefined();
+ v8::Local<v8::String> converted = Nan::New(conv_data->output.c_str()).ToLocalChecked();
+ if (!conv_data->ex.IsNull()) {
+ err = Nan::New(conv_data->ex.Get().what()).ToLocalChecked();
+ }
+ const unsigned argc = 2;
+ v8::Local<v8::Value> argv[argc] = {
+ err,
+ converted
+ };
+ conv_data->callback->Call(argc, argv);
+ delete conv_data;
+ delete req;
+ }
+
+ static NAN_METHOD(ConvertSync) {
+ if (info.Length() < 1 || !info[0]->IsString()) {
+ Nan::ThrowTypeError("Wrong arguments");
+ return;
+ }
+
+ OpenccBinding* instance = Nan::ObjectWrap::Unwrap<OpenccBinding>(info.This());
+
+ const string input = ToUtf8String(info[0]);
+ string output;
+ try {
+ output = instance->Convert(input);
+ } catch (opencc::Exception& e) {
+ Nan::ThrowError(e.what());
+ return;
+ }
+
+ v8::Local<v8::String> converted = Nan::New(output.c_str()).ToLocalChecked();
+ info.GetReturnValue().Set(converted);
+ }
+
+ static NAN_METHOD(GenerateDict) {
+ if (info.Length() < 4 || !info[0]->IsString() || !info[1]->IsString()
+ || !info[2]->IsString() || !info[3]->IsString()) {
+ Nan::ThrowTypeError("Wrong arguments");
+ return;
+ }
+ const string inputFileName = ToUtf8String(info[0]);
+ const string outputFileName = ToUtf8String(info[1]);
+ const string formatFrom = ToUtf8String(info[2]);
+ const string formatTo = ToUtf8String(info[3]);
+ try {
+ opencc::ConvertDictionary(inputFileName, outputFileName, formatFrom, formatTo);
+ } catch (opencc::Exception& e) {
+ Nan::ThrowError(e.what());
+ }
+ }
+
+ static NAN_MODULE_INIT(Init) {
+ // Prepare constructor template
+ v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(OpenccBinding::New);
+ tpl->SetClassName(Nan::New("Opencc").ToLocalChecked());
+ tpl->InstanceTemplate()->SetInternalFieldCount(1);
+ // Methods
+ Nan::SetMethod(tpl, "version", Version);
+ Nan::SetMethod(tpl, "generateDict", GenerateDict);
+ // Prototype
+ Nan::SetPrototypeMethod(tpl, "convert", Convert);
+ Nan::SetPrototypeMethod(tpl, "convertSync", ConvertSync);
+ // Constructor
+ v8::Local<v8::Function> cons = Nan::GetFunction(tpl).ToLocalChecked();
+ Nan::Set(target, Nan::New("Opencc").ToLocalChecked(), cons);
+ }
+};
+
+NODE_MODULE(binding, OpenccBinding::Init);
*/
var path = require('path');
-var binding = require('../build/Release/binding');
+var bindingPath = require('node-pre-gyp').find(require.resolve('../package.json'));
+var binding = require(bindingPath);
-var assetsPath = path.resolve(__dirname, '../build/Release');
+var assetsPath = path.dirname(bindingPath);
var getConfigPath = function (config) {
var configPath = config;
if (config[0] !== '/' && config[1] !== ':') {
"license": "Apache-2.0",
"main": "node/opencc.js",
"scripts": {
- "test": "mocha -R spec node/test.js"
+ "test": "mocha -R spec node/test.js",
+ "deploy": "node-pre-gyp package && (node-pre-gyp-github publish --release || exit 0)",
+ "install": "node-pre-gyp install --fallback-to-build || node-pre-gyp rebuild"
+ },
+ "binary": {
+ "module_name": "opencc",
+ "module_path": "./build/Release/",
+ "host": "https://github.com/BYVoid/OpenCC/releases/download/",
+ "remote_path": "{version}"
},
"repository": {
"type": "git",
"Traditional Chinese"
],
"devDependencies": {
- "mocha": "2.2.5"
+ "mocha": "^3.5.0",
+ "node-pre-gyp-github": "^1.3.1"
},
"dependencies": {
- "nan": "^2.5.1"
+ "nan": "^2.7.0",
+ "node-pre-gyp": "^0.6.36"
}
}
size_t BinaryDict::KeyMaxLength() const {
size_t maxLength = 0;
for (const DictEntry* entry : *lexicon) {
- maxLength = std::max(maxLength, entry->KeyLength());
+ maxLength = (std::max)(maxLength, entry->KeyLength());
}
return maxLength;
}
for (size_t i = 0; i < lexiconCount; i++) {
const DictEntry* entry = lexicon->At(i);
keys[i] = entry->Key();
- maxLength = std::max(entry->KeyLength(), maxLength);
+ maxLength = (std::max)(entry->KeyLength(), maxLength);
}
doubleArray->build(lexicon->Length(), &keys[0]);
dict->lexicon = lexicon;
* Converts a dictionary from a format to another.
* @ingroup opencc_cpp_api
*/
-void ConvertDictionary(const string inputFileName, const string outputFileName,
+OPENCC_EXPORT void ConvertDictionary(const string inputFileName, const string outputFileName,
const string formatFrom, const string formatTo);
}
#include "Export.hpp"
-#ifdef _MSC_VER
-
-// Until Visual Studio 2013 (12.0), C++ 11 "noexcept" qualifier is not supported
+#if defined(_MSC_VER) && _MSC_VER < 1900
+// Before Visual Studio 2015 (14.0), C++ 11 "noexcept" qualifier is not supported
#define noexcept
#endif // ifdef _MSC_VER
* limitations under the License.
*/
+#include <cmath>
+
#include "PhraseExtract.hpp"
#include "TestUtils.hpp"
size_t maxLength = 0;
for (const auto& entry : *lexicon) {
size_t keyLength = entry->KeyLength();
- maxLength = std::max(keyLength, maxLength);
+ maxLength = (std::max)(keyLength, maxLength);
}
return maxLength;
}